<template>
  <div class="app_container">
    <h3 class="module_head">卡内余额统计-管理者</h3>
    <div class="filter-container" style="margin: 0 auto 20px 0;">
      <el-input placeholder="部门id" class="filter-item" v-model="listQuery.deptIdsString"></el-input>
      <el-input placeholder="人员姓名" class="filter-item" v-model="listQuery.personName"></el-input>
      <el-input placeholder="人员工号" class="filter-item" v-model="listQuery.personCode"></el-input>
      <el-button type="primary" icon="el-icon-search" @click="onFilter">
        筛选
      </el-button>
    </div>
    <el-table
      :data="list"
      v-loading="listLoading"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      height="350"
      class="record_table">
      <el-table-column align="center" label="编号" width="90px">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="卡号">
        <template slot-scope="scope">
          {{ scope.row.cardNumber }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="人员姓名">
        <template slot-scope="scope">
          {{ scope.row.personName }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="人员工号">
        <template slot-scope="scope">
          {{ scope.row.personCode }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="部门名称">
        <template slot-scope="scope">
          {{ scope.row.deptName }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="部门id">
        <template slot-scope="scope">
          {{ scope.row.deptId }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="卡内余额">
        <template slot-scope="scope">
          {{ scope.row.balance }}
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="totalPages>0" :total="totalPages" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="fetchData" ></pagination>
  </div>
</template>

<script>
import { getList } from '@/api/balance'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'AdministerBalanceReport',
  components: { Pagination },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      // .then前的函数执行完了才会执行()中的函数
      getList(this.listQuery).then(response => {
        this.list = response.data.items
        // console.log(this.list)
        this.listLoading = false
        this.totalPages = response.data.total
      })
    },
    onFilter() {
      this.listQuery.pageNum = 1
      getList(this.listQuery).then(response => {
        this.list = response.data.items
        this.listLoading = false
        this.totalPages = response.data.total
      })
    }
  },
  data(){
    return {
      list: null,
      listLoading: true,
      listQuery: {
        pageNum: 1,
        pageSize: 20,
        deptIdsString: undefined,
        personName: undefined,
        personCode: undefined,
        queryTime: undefined
      },
      currentPage: 1,
      totalPages: NaN
    }
  }
}
</script>

<style scoped>
.app_container{
  padding: 20px;
}
.module_head{
  margin-top: 0;
}
.filter-item{
  margin-right: 10px;
  width: 130px
}
</style>
